<?php
/**
 * Skeleton Template for Joomla Components
 * Copyright (C) 2009 Think Network GmbH, Munich - All rights reserved.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
 *
 * The "GNU General Public License" (GPL) is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * -----------------------------------------------------------------------------
 * $Id: skeleton.php 1344 2009-06-18 11:50:09Z akede $
 * @package skeleton
 * @subpackage skeleton
 *
*/
defined( 'JPATH_BASE' ) or die( 'Direct Access to this location is not allowed.' );

jimport('joomla.filesystem.path');

/* required standard extentions **/
require_once( JPATH_SITE .DS. 'components' .DS. 'com_skeleton' .DS. 'helpers' .DS. 'defines.php' );
JLoader::register('skeletonVersion', SKELETON_ADMINPATH .DS. 'version.php' );

$cmd = JRequest::getCmd('task', 'default');

if (strpos($cmd, '.') != false) {
	// We have a defined controller/task pair -- lets split them out
	list($controllerName, $task) = explode('.', $cmd);

	// Define the controller name and path
	$controllerName	= strtolower($controllerName);
	$controllerPath	= SKELETON_PATH.DS.'controllers'.DS.$controllerName.'.php';
} else {
	// Base controller, just set the task 
	$controllerName = 'skeleton';
	$controllerPath	= SKELETON_PATH.DS.'controller.php';
	$task = $cmd;
}	
	
// If the controller file path exists, include it ... else lets die with a 500 error
if (file_exists($controllerPath)) {
	require_once($controllerPath);
} else {
	JError::raiseError(500, 'Invalid Controller');
}

// Set the name for the controller and instantiate it
$controllerClass = ucfirst($controllerName).'Controller';
if (class_exists($controllerClass)) {
	$controller = new $controllerClass();
} else {
	JError::raiseError(500, 'Invalid Controller Class - '.$controllerClass );
}

$config	=& JFactory::getConfig();

// Perform the Request task
$controller->execute($task);

// Redirect if set by the controller
$controller->redirect();
$version = new SkeletonVersion();
?><div align="center"><span class="smallgrey">Skeleton Version <?php echo $version->getVersion() .', '. $version->getCopyright();?> Copyright by <a href="http://www.ThinkNetwork.com" target="_blank" class="smallgrey">Think Network</a>, all rights reserved.</span></div>
